﻿/*
{
"状态":1,
"名称":"修改-权限资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"修改-权限资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @power_key int,@power_id varchar(100) ,@power_name varchar(100) , @classify varchar(100) , @remarks varchar(100)
declare @power_id_old varchar(100)

set @power_key = '{power_key}'
set @power_id = '{power_id}'
set @power_name = '{power_name}'
set @classify ='{classify}' 
set @remarks = '{remarks}'

--校验信息
if isnull(@power_id,'')=''
begin 
	RAISERROR ('SQL:权限id不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@power_name,'')=''
begin 
	RAISERROR ('SQL:权限名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@classify,'')=''
begin 
	RAISERROR ('SQL:权限分类不允许为空', 16 ,1 ) ; 
	return 
end 

IF EXISTS(SELECT * FROM y_power WHERE [power_key] <> @power_key and power_id=@power_id)
begin
	RAISERROR ('SQL:权限id已经存在', 16 ,1 ) ; 
	return 
end  

select @power_id_old=power_id from y_power where [power_key] = @power_key

if @power_id_old<>@power_id
Begin 
	update y_menu SET menu_power_id = @power_id,update_time = getdate()
	where menu_power_id= @power_id_old
End

update [dbo].[y_power] set
[power_id] = @power_id ,
[power_name] = @power_name ,
[classify] = @classify ,
[remarks] = @remarks , 
[update_time] = getdate()
where [power_key] = @power_key
